import "es6-promise/auto";
import Vue from 'vue';
/* Vue.config.devtools = true */
import axios from 'axios';
import {
  Loading,
} from 'element-ui';
import App from './app.vue';
import store from './store';
import router from './router';
import Mixin from './mixins';
Vue.mixin(Mixin);

import './element-ui.js';

import './assets/iconfont/iconfont.css';
import './assets/scss/common.scss';
import 'element-ui/lib/theme-chalk/index.css';
/* import 'element-ui/lib/theme-chalk/cascader-panel.css' */
Vue.config.productionTip = false;
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_URL,
  //baseURL:"http://20.20.20.69:9081",
  withCredentials: true,
  timeout: 1000 * 60 * 5
});

// 拦截请求
let loading = null;
service.interceptors.request.use(
  config => {
    // 提示
    loading = Loading.service({
      lock: true,
      text: 'Loading...',
      background: 'rgba(0, 0, 0, 0.7)'
    });
    // IE get请求被缓存
    if ("ActiveXObject" in window && config.method === 'get') {
      config.params = Object.assign(config.params, {
        timestamp: Date.now()
      })
    }
    return config;
  },
  err => {
    loading.close();
    return Promise.reject(err);
  }
);

// 拦截响应
service.interceptors.response.use(
  res => {
    // 提示
    loading.close();
    return res;
  },
  err => {
    loading.close();
    return Promise.reject(err);
  }
);

Vue.$http = Vue.prototype.$http = service;
Vue.$Loading = Vue.prototype.$Loading = Loading;
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')